var path = require('path');
var moment = require('moment');

module.exports = function (app) {
  app.get('/mobile/user/:userId/app/:appId/basicinfo/appversion.json', function (req, res) {
    res.status(200).json({
      "alias": "appVersionId",
      "result": [
        {
          "id": 148,
          "name": "1.1"
        },
        {
          "id": 147,
          "name": "1.2"
        },
        {
          "id": 146,
          "name": "1.3"
        },
        {
          "id": 145,
          "name": "1.4"
        },
        {
          "id": 144,
          "name": "1.5"
        },
        {
          "id": 143,
          "name": "1.6"
        },
        {
          "id": 142,
          "name": "1.7"
        },
        {
          "id": 141,
          "name": "1.8"
        },
        {
          "id": 111,
          "name": "1.9"
        },
        {
          "id": 140,
          "name": "1.10"
        },
        {
          "id": 139,
          "name": "1.11"
        },
        {
          "id": 138,
          "name": "1.12"
        },
        {
          "id": 137,
          "name": "1.13"
        },
        {
          "id": 136,
          "name": "1.14"
        },
        {
          "id": 135,
          "name": "1.15"
        },
        {
          "id": 134,
          "name": "1.16"
        },
        {
          "id": 133,
          "name": "1.17"
        },
        {
          "id": 132,
          "name": "1.18"
        },
        {
          "id": 131,
          "name": "1.19"
        },
        {
          "id": 130,
          "name": "1.20"
        }
      ]
    });
  });

  app.get('/mobile/user/:userId/app/:appId/basicinfo/appChannel.json', function (req, res) {
    res.status(200).json({
      "alias": "",
      "result": [
        {
          "id": 3,
          "name": "360"
        },
        {
          "id": 1,
          "name": "appStore"
        },
        {
          "id": 14,
          "name": "oneapm"
        },
        {
          "id": 11,
          "name": "taobao"
        },
        {
          "id": 5,
          "name": "Wandoujia"
        },
        {
          "id": 7,
          "name": "xiaomi"
        },
        {
          "id": 9,
          "name": "xiaomi2"
        },
        {
          "id": 6,
          "name": "xiaomi3"
        },
        {
          "id": 2,
          "name": "豌豆荚"
        }
      ]
    });
  });

  app.get('/mobile/user/:userId/app/:appId/useranalysis/useradded.json', function (req, res) {
    var json = null;
    switch(req.query.timeUnit) {
      case 'weekly':
        json = [{"count":0,"endTime":1443888000000,"rate":0,"startTime":1443283200000,"val":1},{"count":0,"endTime":1444492800000,"rate":0,"startTime":1443888000000,"val":0}];
        break;
      case 'daily':
        json = [{"count": 100, "endTime": 1443110400000, "rate": 0.2, "startTime": 1443074061397, "val": 20 }, {"count": 150, "endTime": 1443196800000, "rate": 2, "startTime": 1443110400000, "val": 300 }, {"count": 300, "endTime": 1443283200000, "rate": 2.67, "startTime": 1443196800000, "val": 800 }, {"count": 300, "endTime": 1443369600000, "rate": 2, "startTime": 1443283200000, "val": 600 }, {"count": 280, "endTime": 1443456000000, "rate": 0.35, "startTime": 1443369600000, "val": 10 }, {"count": 300, "endTime": 1443542400000, "rate": 0.18, "startTime": 1443456000000, "val": 55 }, {"count": 330, "endTime": 1443628800000, "rate": 0.06, "startTime": 1443542400000, "val": 21 }, {"count": 0, "endTime": 1443715200000, "rate": 0, "startTime": 1443628800000, "val": 0 }, {"count": 0, "endTime": 1443801600000, "rate": 0, "startTime": 1443715200000, "val": 0 }, {"count": 0, "endTime": 1443888000000, "rate": 0, "startTime": 1443801600000, "val": 0 }, {"count": 0, "endTime": 1443974400000, "rate": 0, "startTime": 1443888000000, "val": 0 }, {"count": 0, "endTime": 1444060800000, "rate": 0, "startTime": 1443974400000, "val": 0 }, {"count": 0, "endTime": 1444147200000, "rate": 0, "startTime": 1444060800000, "val": 0 }, {"count": 0, "endTime": 1444233600000, "rate": 0, "startTime": 1444147200000, "val": 88 }, {"count": 0, "endTime": 1444320000000, "rate": 0, "startTime": 1444233600000, "val": 0 }, {"count": 0, "endTime": 1444406400000, "rate": 0, "startTime": 1444320000000, "val": 0 } ];
        break;
      case 'monthly':
        json = [{"count":0,"endTime":1443628800000,"rate":0,"startTime":1441036800000,"val":0},{"count":0,"endTime":1446307200000,"startTime":1443628800000,"val":1}];
        break;
      default:
        break;
    }
    res.status(200).json(json);
  });

  app.get('/mobile/user/:userId/app/:appId/useranalysis/useraddedexportxls', function (req, res) {
    res.download(path.join(__dirname, 'abc.xlsx'), 'abc.xlsx', function (err) {
      if (err) {
        console.log(err);
      };
    });
  });


  app.get('/mobile/user/:userId/app/:appId/useranalysis/useralive.json', function (req, res) {
    var json = null;
    switch(req.query.timeUnit) {
      case 'weekly':
        json = [{
                    "count": 230,
                    "endTime": moment().subtract(7, 'days').startOf('day').valueOf(),
                    "startTime": moment().subtract(14, 'days').startOf('day').valueOf(),
                    "val": 67,
                    "rate": 0.35
                },
                {
                    "count": 572,
                    "endTime": moment().startOf('day').valueOf(),
                    "startTime": moment().subtract(7, 'days').startOf('day').valueOf(),
                    "val": 100,
                    "rate": 0.18
                }];
        break;
      case 'daily':
        json = [
                {
                    "count": 100,
                    "endTime": moment().subtract(22, 'days').startOf('day').valueOf(),
                    "startTime": moment().subtract(23, 'days').startOf('day').valueOf(),
                    "val": 21,
                    "rate": 0.21
                },
                {
                    "count": 1000,
                    "endTime": moment().subtract(21, 'days').startOf('day').valueOf(),
                    "startTime": moment().subtract(22, 'days').startOf('day').valueOf(),
                    "val": 76,
                    "rate": 0.076
                },
                {
                    "count": 1000,
                    "endTime": moment().subtract(20, 'days').startOf('day').valueOf(),
                    "startTime": moment().subtract(21, 'days').startOf('day').valueOf(),
                    "val": 50,
                    "rate": 0.054356
                },
                {
                    "count": 100,
                    "endTime": moment().subtract(19, 'days').startOf('day').valueOf(),
                    "startTime": moment().subtract(20, 'days').startOf('day').valueOf(),
                    "val": 24,
                    "rate": Math.random()
                },

                {
                    "count": 1000,
                    "endTime": moment().subtract(18, 'days').startOf('day').valueOf(),
                    "startTime": moment().subtract(19, 'days').startOf('day').valueOf(),
                    "val": 250,
                    "rate": Math.random()
                },
                {
                    "count": 100,
                    "endTime": moment().subtract(17, 'days').startOf('day').valueOf(),
                    "startTime": moment().subtract(18, 'days').startOf('day').valueOf(),
                    "val": 26,
                    "rate": 0.267891
                },
                {
                    "count": 100,
                    "endTime": moment().subtract(16, 'days').startOf('day').valueOf(),
                    "startTime": moment().subtract(17, 'days').startOf('day').valueOf(),
                    "val": 27,
                    "rate": Math.random()
                },

                {
                    "count": 100,
                    "endTime": moment().subtract(15, 'days').startOf('day').valueOf(),
                    "startTime": moment().subtract(16, 'days').startOf('day').valueOf(),
                    "val": 20,
                    "rate": 0.20
                },
                {
                    "count": 1150,
                    "endTime": moment().subtract(14, 'days').startOf('day').valueOf(),
                    "startTime": moment().subtract(15, 'days').startOf('day').valueOf(),
                    "val": 300,
                    "rate": Math.random()
                },
                {
                    "count": 1300,
                    "endTime": moment().subtract(13, 'days').startOf('day').valueOf(),
                    "startTime": moment().subtract(14, 'days').startOf('day').valueOf(),
                    "val": 800,
                    "rate": 0.67
                },
                {
                    "count": 300,
                    "endTime": moment().subtract(12, 'days').startOf('day').valueOf(),
                    "startTime": moment().subtract(13, 'days').startOf('day').valueOf(),
                    "val": 600,
                    "rate": 0.12
                },
                {
                    "count": 280,
                    "endTime": moment().subtract(11, 'days').startOf('day').valueOf(),
                    "startTime": moment().subtract(12, 'days').startOf('day').valueOf(),
                    "val": 110,
                    "rate": Math.random()
                },
                {
                    "count": 300,
                    "endTime": moment().subtract(10, 'days').startOf('day').valueOf(),
                    "startTime": moment().subtract(11, 'days').startOf('day').valueOf(),
                    "val": 55,
                    "rate": 0.18
                },
                {
                    "count": 330,
                    "endTime": moment().subtract(9, 'days').startOf('day').valueOf(),
                    "startTime": moment().subtract(10, 'days').startOf('day').valueOf(),
                    "val": 21,
                    "rate": 0.06
                },
                {
                    "count": 30,
                    "endTime": moment().subtract(8, 'days').startOf('day').valueOf(),
                    "startTime": moment().subtract(9, 'days').startOf('day').valueOf(),
                    "val": 10,
                    "rate": 0.3
                },
                {
                    "count": 1230,
                    "endTime": moment().subtract(7, 'days').startOf('day').valueOf(),
                    "startTime": moment().subtract(8, 'days').startOf('day').valueOf(),
                    "val": 110,
                    "rate": 0.11
                },
                {
                    "count": 30,
                    "endTime": moment().subtract(6, 'days').startOf('day').valueOf(),
                    "startTime": moment().subtract(7, 'days').startOf('day').valueOf(),
                    "val": 2,
                    "rate": 0.07
                },
                {
                    "count": 0,
                    "endTime": moment().subtract(5, 'days').startOf('day').valueOf(),
                    "startTime": moment().subtract(6, 'days').startOf('day').valueOf(),
                    "val": 0,
                    "rate": 0
                },
                {
                    "count": 120,
                    "endTime": moment().subtract(4, 'days').startOf('day').valueOf(),
                    "startTime": moment().subtract(5, 'days').startOf('day').valueOf(),
                    "val": 20,
                    "rate": 0.17
                },
                {
                    "count": 542,
                    "endTime": moment().subtract(3, 'days').startOf('day').valueOf(),
                    "startTime": moment().subtract(4, 'days').startOf('day').valueOf(),
                    "val": 108,
                    "rate": 0.2
                },
                {
                    "count": 0,
                    "endTime": moment().subtract(2, 'days').startOf('day').valueOf(),
                    "startTime": moment().subtract(3, 'days').startOf('day').valueOf(),
                    "val": 0
                },
                {
                    "count": 100,
                    "endTime": moment().subtract(1, 'days').startOf('day').valueOf(),
                    "startTime": moment().subtract(2, 'days').startOf('day').valueOf(),
                    "val": 23,
                    "rate": 0.23
                },
                {
                    "count": 10,
                    "endTime": moment().startOf('day').valueOf(),
                    "startTime": moment().subtract(1, 'days').startOf('day').valueOf(),
                    "val": 1,
                    "rate": 0.1
                }];
        break;
      case 'monthly':
        json = [{
                    "count": 641,
                    "endTime": moment().subtract(1, 'month').startOf('day').valueOf(),
                    "startTime": moment().subtract(2, 'month').startOf('day').valueOf(),
                    "val": 123,
                    "rate": 0.23
                },
                {
                    "count": 0,
                    "endTime": moment().startOf('day').valueOf(),
                    "startTime": moment().subtract(1, 'month').startOf('day').valueOf(),
                    "val": 0
                }];
        break;
      default:
        break;
    }
    setTimeout(function(){res.status(200).json(json)},800);
    // res.status(200).json(json);
  });

  app.get('/mobile/user/:userId/app/:appId/useranalysis/useraliveexportxls', function (req, res) {
    res.download(path.join(__dirname, 'abc.xlsx'), 'ABC.xlsx', function (err) {
      if (err) {
        console.log(err);
      };
    });
  });


  app.get('/mobile/user/:userId/app/:appId/useranalysis/userhourlyalive.json', function (req, res) {
    var json = null;
    switch(req.query.timeUnit) {
      case 'weekly':
        json = [
                {
                    "hour": 0,
                    "aliveNum": 1234,
                    "startNum": 234
                },
                {
                    "hour": 1,
                    "aliveNum": 238,
                    "startNum": 23
                },
                {
                    "hour": 2,
                    "aliveNum": 197,
                    "startNum": 121
                },
                {
                    "hour": 3,
                    "aliveNum": 145,
                    "startNum": 77
                },

                {
                    "hour": 4,
                    "aliveNum": 345,
                    "startNum": 45
                },
                {
                    "hour": 5,
                    "aliveNum": 234,
                    "startNum": 56
                },
                {
                    "hour": 6,
                    "aliveNum": 134,
                    "startNum": 34
                },
                {
                    "hour": 7,
                    "aliveNum": 777,
                    "startNum": 122
                },
                {
                    "hour": 8,
                    "aliveNum": 897,
                    "startNum": 222
                },
                {
                    "hour": 9,
                    "aliveNum": 1345,
                    "startNum": 345
                },
                {
                    "hour": 10,
                    "aliveNum": 2222,
                    "startNum": 856
                },
                {
                    "hour": 11,
                    "aliveNum": 1343,
                    "startNum": 523
                },
                {
                    "hour": 12,
                    "aliveNum": 8888,
                    "startNum": 2234
                },
                {
                    "hour": 13,
                    "aliveNum": 3452,
                    "startNum": 1724
                },
                {
                    "hour": 14,
                    "aliveNum": 2342,
                    "startNum": 1789
                },
                {
                    "hour": 15,
                    "aliveNum": 1232,
                    "startNum": 568
                },
                {
                    "hour": 16,
                    "aliveNum": 777,
                    "startNum": 345
                },
                {
                    "hour": 17,
                    "aliveNum": 999,
                    "startNum": 234
                },
                {
                    "hour": 18,
                    "aliveNum": 1233,
                    "startNum": 689
                },
                {
                    "hour": 19,
                    "aliveNum": 4000,
                    "startNum": 2999
                },
                {
                    "hour": 20,
                    "aliveNum": 3001,
                    'startNum': 4400
                },
                {
                    "hour": 21,
                    "aliveNum": 2601,
                    "startNum": 2345
                },
                {
                    "hour": 22,
                    "aliveNum": 1098,
                    "startNum": 563
                },
                {
                    "hour": 23,
                    "aliveNum": 689,
                    "startNum": 123
                }];
        break;
      case 'daily':
        json = [
                {
                    "hour": 0,
                    "aliveNum": 123,
                    "startNum": 23
                },
                {
                    "hour": 1,
                    "aliveNum": 23,
                    "startNum": 2
                },
                {
                    "hour": 2,
                    "aliveNum": 29,
                    "startNum": 11
                },
                {
                    "hour": 3,
                    "aliveNum": 1114,
                    "startNum": 234
                },

                {
                    "hour": 4,
                    "aliveNum": 34,
                    "startNum": 424
                },
                {
                    "hour": 5,
                    "aliveNum": 23,
                    "startNum": 125
                },
                {
                    "hour": 6,
                    "aliveNum": 13,
                    "startNum": 333
                },
                {
                    "hour": 7,
                    "aliveNum": 77,
                    "startNum": 212
                },
                {
                    "hour": 8,
                    "aliveNum": 289,
                    "startNum": 622
                },
                {
                    "hour": 9,
                    "aliveNum": 134,
                    "startNum": 34
                },
                {
                    "hour": 10,
                    "aliveNum": 222,
                    "startNum": 85
                },
                {
                    "hour": 11,
                    "aliveNum": 134,
                    "startNum": 52
                },
                {
                    "hour": 12,
                    "aliveNum": 888,
                    "startNum": 223
                },
                {
                    "hour": 13,
                    "aliveNum": 345,
                    "startNum": 172
                },
                {
                    "hour": 14,
                    "aliveNum": 234,
                    "startNum": 178
                },
                {
                    "hour": 15,
                    "aliveNum": 123,
                    "startNum": 56
                },
                {
                    "hour": 16,
                    "aliveNum": 77,
                    "startNum": 34
                },
                {
                    "hour": 17,
                    "aliveNum": 99,
                    "startNum": 23
                },
                {
                    "hour": 18,
                    "aliveNum": 123,
                    "startNum": 68
                },
                {
                    "hour": 19,
                    "aliveNum": 400,
                    "startNum": 299
                },
                {
                    "hour": 20,
                    "aliveNum": 300,
                    'startNum': 440
                },
                {
                    "hour": 21,
                    "aliveNum": 260,
                    "startNum": 234
                },
                {
                    "hour": 22,
                    "aliveNum": 109,
                    "startNum": 56
                },
                {
                    "hour": 23,
                    "aliveNum": 68,
                    "startNum": 612
                }];
        break;
      case 'monthly':
        json = [
                {
                    "hour": 0,
                    "aliveNum": 12345,
                    "startNum": 1234
                },
                {
                    "hour": 1,
                    "aliveNum": 2385,
                    "startNum": 123
                },
                {
                    "hour": 2,
                    "aliveNum": 975,
                    "startNum": 112
                },
                {
                    "hour": 3,
                    "aliveNum": 455,
                    "startNum": 17
                },

                {
                    "hour": 4,
                    "aliveNum": 3455,
                    "startNum": 145
                },
                {
                    "hour": 5,
                    "aliveNum": 2345,
                    "startNum": 156
                },
                {
                    "hour": 6,
                    "aliveNum": 1345,
                    "startNum": 134
                },
                {
                    "hour": 7,
                    "aliveNum": 7775,
                    "startNum": 1122
                },
                {
                    "hour": 8,
                    "aliveNum": 8975,
                    "startNum": 1222
                },
                {
                    "hour": 9,
                    "aliveNum": 13455,
                    "startNum": 1345
                },
                {
                    "hour": 10,
                    "aliveNum": 22225,
                    "startNum": 1856
                },
                {
                    "hour": 11,
                    "aliveNum": 13435,
                    "startNum": 1523
                },
                {
                    "hour": 12,
                    "aliveNum": 88885,
                    "startNum": 12234
                },
                {
                    "hour": 13,
                    "aliveNum": 34525,
                    "startNum": 11724
                },
                {
                    "hour": 14,
                    "aliveNum": 23425,
                    "startNum": 11789
                },
                {
                    "hour": 15,
                    "aliveNum": 12325,
                    "startNum": 1568
                },
                {
                    "hour": 16,
                    "aliveNum": 7775,
                    "startNum": 1345
                },
                {
                    "hour": 17,
                    "aliveNum": 9995,
                    "startNum": 1234
                },
                {
                    "hour": 18,
                    "aliveNum": 12335,
                    "startNum": 1689
                },
                {
                    "hour": 19,
                    "aliveNum": 40005,
                    "startNum": 12999
                },
                {
                    "hour": 20,
                    "aliveNum": 30015,
                    'startNum': 14400
                },
                {
                    "hour": 21,
                    "aliveNum": 26015,
                    "startNum": 12345
                },
                {
                    "hour": 22,
                    "aliveNum": 10985,
                    "startNum": 1563
                },
                {
                    "hour": 23,
                    "aliveNum": 6895,
                    "startNum": 1123
                }];
        break;
      default:
        break;
    }
    setTimeout(function(){res.status(200).json(json)}, 500);
  });

};
